/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Order.Entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Administrator
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Orderline.findAll", query = "select o from OrderLine o"),
    @NamedQuery(name = "Orderline.findOrderlineById", query = "select o from OrderLine o where o.id = :id")
})
@Table(name = "orderlines")
public class OrderLine implements Serializable {
    @Id
    @Column(name = "ID")
    private Integer id;
    @Column(name = "quantity")
    private Integer quantity;
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "product_id")
    private Product product;
    @ManyToOne
    @JoinColumn(name = "order_id", insertable = true, updatable = true)
    private Order order;
    @Transient
    private String action;

    public OrderLine() {
    }

    public OrderLine(Integer id, Integer quantity,
            Product product, Order order, String action) {
        this.order = order;
        this.id = id;
        this.quantity = quantity;
        this.product = product;
        this.action = action;
    }

    public String getAction() {
        return action;
    }

    @Transient
    public void setAction(String action) {
        this.action = action;
    }

    public Integer getOrder_Id() {
        return order.getId();
    }

    @Id
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    @XmlTransient
    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
        if (order != null) {
            this.id = order.getId();
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof OrderLine)) {
            return false;
        }
        OrderLine other = (OrderLine) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Order.Entity.OrderLine[id=" + id + "]";
    }
}
